{extend name="common/main"/}

{block name="body"}
    <div class="main-title cf">
        <h2>
            {if condition="request()->action() eq 'addaction'"}
                {:lang("_NEWLY_ADDED_")}
            {else/}
                {:lang("_EDIT_")}
            {/if}
                {:lang("_BEHAVIOR_")}
        </h2>
    </div>
    <!-- 表单 -->
    <div class="with-padding">
        <form id="form" action="{:url()}" method="post" class="form-horizontal">
            <div class="form-item builder_item">
                <label class="item-label">{:lang("_BEHAVIOR_IDENTIFICATION_")}<span class="check-tips">{:lang("_ENTER_THE_BEHAVIOR_TO_IDENTIFY_AN_ENGLISH_LETTER_WITH_SPACE_")}</span></label>

                <div class="controls">
                    <input type="text" class="text input-large form-control form-input-width" name="name"
                           value="{$data.name}">
                </div>
            </div>
            <div class="form-item builder_item">
                <label class="item-label">{:lang("_BEHAVIOR_NAME_")}<span class="check-tips">{:lang("_ENTER_THE_ACTION_NAME_")}</span></label>

                <div class="controls">
                    <input type="text" class="text input-large form-control form-input-width" name="title"
                           value="{$data.title}">
                </div>
            </div>
            <div class="form-item builder_item">
                <label class="item-label">{:lang("_BEHAVIOR_TYPE_")}<span class="check-tips">{:lang("_CHOICE_BEHAVIOR_TYPE_")}</span></label>

                <div class="controls">
                    <select name="type" class=" form-control form-select-size">
                        {volist name=":get_action_type(null,true)" id="vo"}
                            <option value="{$key}">{$vo}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="form-item builder_item">
                <label class="item-label">{:lang("_THE_MODULE_")}<span class="check-tips">{:lang("_SELECTION_MODULE_")}</span></label>

                <div class="controls">
                    <select name="module" class=" form-control form-select-size">
                        <option value="">{:lang("_SYSTEM_")}</option>
                        {volist name="module" id="vo"}
                            <option value="{$vo.name}"
                            {php} if($vo['name'] == $data['module']){{/php}
                            selected
                            {php}}{/php}
                            >{$vo.alias}</option>
                        {/volist}
                    </select>
                </div>
            </div>


            <div class="form-item builder_item">
                <label class="item-label">{:lang("_BEHAVIOR_DESCRIPTION_")}<span class="check-tips">{:lang("_INPUT_BEHAVIOR_DESCRIPTION_")}</span></label>

                <div class="controls">
                    <textarea name="remark" class=" form-control form-text-area-size">{$data.remark}</textarea>
                </div>
            </div>

            <div class="form-item builder_item">
                <label class="item-label">{:lang("_INTEGRAL_RULE_")}<span class="check-tips">{:lang("_ENTER_THE_INTEGRATION_RULE_NOT_WRITE_THE_LOG_ONLY_")}</span></label>

                <div class="controls action_rule">
                    {php}
                        $score = model('ucenter/Score')->getTypeList(array('status'=>1));
                        $data['rule'] = unserialize( $data['rule']);
                    {/php}

                    {php}if(empty($data['rule'])){{/php}
                        {:lang("_NO_RULES_")}
                    {php}}{/php}

                    <div class="clearfix">
                        <div class="pull-left text-center" style="width: 100px">
                           {:lang("_TABLE_NAME_")}
                        </div>
                        <div class="pull-left text-center" style="width: 100px">
                           {:lang("_INTEGRAL_TYPE_")}
                        </div>
                        <div class="pull-left text-center" style="width: 100px">
                           {:lang("_INTEGRAL_OPERATION_")}
                        </div>
                        <div class="pull-left text-center" style="width: 100px">
                           {:lang("_PERIOD_HOURS_")}
                        </div>
                        <div class="pull-left text-center" style="width: 100px">
                           {:lang("_MAXIMUM_LIMIT_SECOND_")}
                        </div>
                    </div>
                    {volist name="data['rule']" id="rule"}
                        <div style="margin-bottom: 10px">
                            <input class="form-control" name="action_rule[table][]" value="{$rule.table}"
                                   title={:lang("_THE_TABLE_THAT_IS_EXECUTED_THE_DEFAULT_IS_MEMBER_WITH_DOUBLE_")} style="width: 100px;display: inline-block">
                            <select class="form-control" name="action_rule[field][]" title={:lang("_INTEGRAL_OF_EXECUTION_WITH_DOUBLE_")}
                                    style="width: 100px;display: inline-block">
                                <option value="0">{:lang("_PLEASE_CHOOSE_")}</option>
                                {volist name="score" id="s"}
                                    <option value="{$s.id}" {if condition="$s['id'] eq $rule['field']"}selected{/if}>
                                        {$s.title}
                                    </option>
                                {/volist}
                            </select>
                            <input type="text" name="action_rule[rule][]" title={:lang("_THE_INTEGRAL_OPERATION_THE_MINUS_INTEGRAL_WITH_DOUBLE_")} value="{$rule.rule}"
                                   class=" form-control" style="width: 100px;display: inline-block"/>
                            <input class="form-control" name="action_rule[cycle][]" title={:lang("_PERIOD_WITH_DOUBLE_")} value="{$rule.cycle}"
                                   style="width: 100px;display: inline-block">
                            <input class="form-control" name="action_rule[max][]" title={:lang("_MAXIMUM_LIMIT_WITH_DOUBLE_")} value="{$rule.max}"
                                   style="width: 100px;display: inline-block">
                            <a href="javascript:" data-role="del_rule">{:lang("_DELETE_RULE_")}</a>

                        </div>
                    {/volist}
                </div>
                <a href="javascript:" data-role="add_rule">{:lang("_NEW_RULES_")}</a>
            </div>

            <div class="form-item builder_item">
                <label class="item-label">
                    {:lang("_LOG_RULE_")}
                    <span class="check-tips">
                        {:lang("_TO_GENERATE_SUPPORT_AND_SUPPORT_THE_RULE_TO_BE_GENERATED_BY_THIS_RULE_")}[{:lang("_VARIABLE_")}|{:lang("_FUNCTION_")}]。{:lang("_CURRENT_VARIABLES_")}{:lang("_COLON_")}user,time,model,record,data）
                    </span>
                </label>

                <div class="controls">
                    <textarea name="log" class=" form-control form-text-area-size">{$data.log}</textarea>
                </div>
            </div>

            <div class="form-item builder_item">
                <input type="hidden" name="id" value="{$data.id}"/>
                <button type="submit" class="btn btn-success submit-btn ajax-post" target-form="form-horizontal">{:lang("_SURE_WITH_SPACE_")}</button>
                <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">{:lang("_RETURN_WITH_SPACE_")}</button>
            </div>
        </form>
    </div>


    <div id="rule_list" style="display: none">
        <div style="margin-bottom: 10px">
            <input class="form-control" name="action_rule[table][]" value="member" title={:lang("_THE_TABLE_THAT_IS_EXECUTED_THE_DEFAULT_IS_MEMBER_WITH_DOUBLE_")}
                   style="width: 100px;display: inline-block">
            <select class="form-control" name="action_rule[field][]" title={:lang("_INTEGRAL_OF_EXECUTION_WITH_DOUBLE_")}
                    style="width: 100px;display: inline-block">
                <option value="0">{:lang("_PLEASE_CHOOSE_")}</option>
                {volist name="score" id="s"}
                    <option value="{$s.id}">{$s.title}</option>
                {/volist}
            </select>
            <input type="text" name="action_rule[rule][]" title={:lang("_THE_INTEGRAL_OPERATION_THE_MINUS_INTEGRAL_WITH_DOUBLE_")} value="0" class=" form-control"
                   style="width: 100px;display: inline-block"/>
            <input class="form-control" name="action_rule[cycle][]" title={:lang("_PERIOD_HOURS_WITH_DOUBLE_")} value="24"
                   style="width: 100px;display: inline-block">
            <input class="form-control" name="action_rule[max][]" title={:lang("_MAXIMUM_LIMIT_SECOND_WITH_DOUBLE_")} value="1"
                   style="width: 100px;display: inline-block">
            <a href="javascript:" data-role="del_rule">{:lang("_DELETE_RULE_")}</a>
        </div>
    </div>
{/block}
{block name="script"}
    <script type="text/javascript" charset="utf-8">
        Think.setValue('type', {$data.type|default = 1});
    </script>

    <script>
        $(function () {
            rebind();
        })

        var rebind = function () {
            add_rule();
            del_rule();
        }
        var add_rule = function () {

            $('[data-role="add_rule"]').unbind('click');
            $('[data-role="add_rule"]').click(function () {
                $('.action_rule').append($('#rule_list').html())
                rebind();
            })

        }

        var del_rule = function () {
            $('[data-role="del_rule"]').unbind('click');
            $('[data-role="del_rule"]').click(function () {
                $(this).closest('div').remove();
                rebind();
            })
        }

    </script>
{/block}
